/*
 * create_rxthreads.c
 * Created on April 11, 2008; 3:19 PM
 * by VRamadurai
 */
#include <pthread.h>
#include <sched.h>
#include "HsTypes.h"

/** Stack for PHY **/
#define THREAD1_STACKSIZE	(3*1024)
#define THREAD2_STACKSIZE	(3*1024)

hs_uint8_t PhyStackBuffer1[THREAD1_STACKSIZE];
hs_uint8_t PhyStackBuffer2[THREAD2_STACKSIZE];

/** SB3500 RX THREADS **/
void* FnThread2(void *);
void* FnThread3(void *);
void* (*FnThreadRx[2])(void *) = {
    FnThread2,
    FnThread3,
};

void create_rx_threads()
{
    hs_int32_t siIndex;
    hs_int32_t siThreadSuccessFlag;
    static pthread_attr_t ThreadAttr;
    static struct sched_param sSched;
    static hs_int32_t num[8];
    static pthread_t thread_t;

    /* Initialising thread attributes */
    pthread_attr_init(&ThreadAttr);
    sSched.sched_priority = 0;
    pthread_attr_setschedpolicy(&ThreadAttr, SCHED_PIN);

    /** 2 threads on Core 1 **/
    for(siIndex=0; siIndex<2; siIndex++)
    {
        pthread_attr_setcore_sb(&ThreadAttr, 0);
        num[siIndex] = siIndex+1;
        sSched.sched_cpuset = 1<<(siIndex+1);
        pthread_attr_setschedparam(&ThreadAttr,&sSched);

        if(siIndex == 0){
        	pthread_attr_setstackaddr(&ThreadAttr, PhyStackBuffer1);
            pthread_attr_setstacksize(&ThreadAttr, THREAD1_STACKSIZE);
        }
        else{
        	pthread_attr_setstackaddr(&ThreadAttr, PhyStackBuffer2);
            pthread_attr_setstacksize(&ThreadAttr, THREAD2_STACKSIZE);
        }

        siThreadSuccessFlag = pthread_create(&thread_t,&ThreadAttr,FnThreadRx[siIndex],(void*)&num[siIndex]);
        if(siThreadSuccessFlag != 0)
        {
           printf(" UnsuccessFull Thread %d Creation %d \n", siIndex, siThreadSuccessFlag);
        }
        else{
            printf(" SuccessFull Thread %d Creation %d \n", siIndex, siThreadSuccessFlag);
        }
    }
}
